from django.db import models

# Create your models here.
class A(models.Model):
    a = models.CharField(max_length=5)


class B(models.Model):
    a = models.CharField(max_length=5)
    b = models.OneToOneField(A)

class C(models.Model):
    a = models.CharField(max_length=5)
    c = models.ManyToManyField(A, blank=True, null=True)

    @staticmethod
    def get_c(c=None):
        if c:
            return C.objects.filter(id=c.id).values_list('c', 'c__a', flat=False)
        return None
    
    # >>> from app.models import *
    # >>> c=C.objects.get(id=7)
    # >>> C.get_c(c)
    # [(1L, u'a'), (2L, u'b'), (3L, u'adf'), (4L, u'adaf'), (5L, u'adadf')]